package com.fortune.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fortune.base.BaseAPIExcution;
import com.fortune.common.paging.PagingData;
import com.fortune.constants.Constants;
import com.fortune.dto.excution.MDataAnalysisExcution;
import com.fortune.dto.in.mDataAnalysis.MProductStoreDetailListDto;
import com.fortune.dto.in.mDataAnalysis.OrderCollectionDto;
import com.fortune.entity.MProductStockDetailInfo;
import com.fortune.entity.MUserInfo;
import com.fortune.enums.MDataAnalysisEnum;
import com.fortune.service.MDataAnalysisService;
import com.fortune.vo.mDataAnalysis.OrderCollection;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@Api(value = "mDataAnalysis", description = "厂商数据分析", tags = {"厂商数据分析"})
@RestController
@RequestMapping("mDataAnalysis")
public class MDataAnalysisController {
	
	@Autowired
	private MDataAnalysisService mDataAnalysisService;
	
	@ApiOperation(value = "商品库存明细表", nickname = "mProductStoreDetailList", notes = "", tags={ "@岳希伟" })
	@ApiImplicitParams({
		@ApiImplicitParam(name="page", value="第几页",paramType="query",dataType="int"),
		@ApiImplicitParam(name="length", value="每页容量",paramType="query",dataType="int"),
		@ApiImplicitParam(name="storeId", value="仓库id",paramType="query",dataType="String"),
		@ApiImplicitParam(name="mpid", value="商品id",paramType="query",dataType="string")
	})
    @GetMapping(value = "list",
        produces = { MediaType.APPLICATION_JSON_VALUE })
	public BaseAPIExcution<PagingData<MProductStockDetailInfo>> mProductStoreDetail(HttpServletRequest request,@Validated @ApiIgnore MProductStoreDetailListDto listDto){
		HttpSession session = request.getSession();
		MUserInfo mUserInfo = (MUserInfo) session.getAttribute(Constants.SESSION_M_USER);
		listDto.setPage((listDto.getPage()-1)*10);
		PagingData<MProductStockDetailInfo> pagingData = mDataAnalysisService.mProductStoreDetailList(mUserInfo, listDto);
		return new MDataAnalysisExcution<PagingData<MProductStockDetailInfo>>(pagingData, MDataAnalysisEnum.SUCESS);
	}
	
	@ApiOperation(value = "经销商订货汇总表", nickname = "OrderCollection", notes = "", tags={ "@岳希伟" })
	@ApiImplicitParams({
		@ApiImplicitParam(name="startTime", value="开始时间",paramType="query",dataType="String"),
		@ApiImplicitParam(name="endTime", value="结束时间",paramType="query",dataType="string")
	})
	@GetMapping(value = "OrderCollection",
	        produces = { MediaType.APPLICATION_JSON_VALUE })
		public BaseAPIExcution<List<OrderCollection>> orderCollection(HttpServletRequest request,@Validated @ApiIgnore OrderCollectionDto orderDto){
			HttpSession session = request.getSession();
			MUserInfo mUserInfo = (MUserInfo) session.getAttribute(Constants.SESSION_M_USER);
			mDataAnalysisService.orderCollection(mUserInfo,orderDto);
			return new MDataAnalysisExcution<List<OrderCollection>>(null, MDataAnalysisEnum.SUCESS);
		}
}
